//
// Created by Yun on 2021/11/13.
//
#pragma once

#include "VulkanDefine.h"

#define GLFW_INCLUDE_NONE
#include <GLFW/glfw3.h>
#define GLFW_EXPOSE_NATIVE_WIN32
#include <GLFW/glfw3native.h>

#include "MathHelp.h"
#include "EventSystem.h"

class GLWindow
{
public:
    ~GLWindow();
    GLWindow(const GLWindow&) = delete;
    GLWindow& operator=(const GLWindow&) = delete;

    static GLWindowRef create(int width, int height, const std::string& title = "");

    void update();

    const math::Vec2& getSize() const { return size; }

    float getAspectRatio() const { return size.x/ size.y; }

    float getWidth() const { return size.x; }
    float getHeight() const { return size.y; }
    GLFWwindow* getGlfwWindow() const { return glfwWindow; }
    HWND getHwnd() const { return glfwGetWin32Window(glfwWindow); }
    bool shouldClose() const { return glfwWindowShouldClose(glfwWindow); }

    void setSize(int width, int height);
    void SwapBuffers() {glfwSwapBuffers(glfwWindow);}

    bool resizable{true};
private:
    GLWindow() = default;
    bool init(int width, int height, const std::string& title);

    math::Vec2 size;
    GLFWwindow* glfwWindow = nullptr;

    MouseEvent mouseEvent;
    KeyEvent keyEvent;
    WindowEvent windowEvent;
};
